/**
 * 
 */
package jm.lib.common.db;



/**
 * @author JimingLiu
 *
 */
public class Order {
    private String column;
    private boolean desc;
    
    /**
     * @param column
     * @param desc
     */
    public Order(String column, boolean desc) {
        super();
        this.column = column;
        this.desc = desc;
    }

    public static Order asc(String property_name) {
        return new Order(property_name, false);
    }
    
    public static Order desc(String property_name) {
        return new Order(property_name, true);
    }
    
    public String toString() {
      return desc?column + " DESC":column; 
    }

    /**
     * Returns <code>true</code> if this <code>OrderItem</code> is the same as the o argument.
     *
     * @return <code>true</code> if this <code>OrderItem</code> is the same as the o argument.
     */
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null) {
            return false;
        }
        if (o.getClass() != getClass()) {
            return false;
        }
        Order castedObj = (Order) o;
        return ((this.column == null ? castedObj.column == null : this.column
            .equals(castedObj.column)) && (this.desc == castedObj.desc));
    }

    /**
     * Override hashCode.
     *
     * @return the Objects hashcode.
     */
    public int hashCode() {
        int hashCode = 1;
        hashCode = 31 * hashCode + (column == null ? 0 : column.hashCode());
        hashCode = 31 * hashCode + (desc ? 1231 : 1237);
        return hashCode;
    }

    /**
     * @return the column
     */
    public String getColumn() {
        return column;
    }

    /**
     * @param column the column to set
     */
    public void setColumn(String column) {
        this.column = column;
    }

    /**
     * @return the desc
     */
    public boolean isDesc() {
        return desc;
    }

    /**
     * @param desc the desc to set
     */
    public void setDesc(boolean desc) {
        this.desc = desc;
    }
}
